#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>

int main(int argc, char *argv[])
{
	char *login;
	struct passwd *pentry;

	if((login=getlogin())==NULL)
	{
		perror("getlogin");
		exit(EXIT_FAILURE);
	}
	if((pentry=getpwnam(login))==NULL)
	{
		perror("getpwnam");
		exit(EXIT_FAILURE);
	}

	//cout<<"print pid:\n"; //why cannot use cout?
	printf("PID=%d\n",getpid());
	printf("PPID=%d\n",getppid());
	printf("Real user ID = %d\n",getuid());
	printf("Effective user ID = %d\n",geteuid());
	printf("Real group ID = %d\n",getgid());
	printf("Effective group ID = %d\n",getegid());

	printf("\n==========================\n");
	printf("User name: %s\n",pentry->pw_name);
	printf("UID name: %d\n",pentry->pw_uid);
	printf("GID: %d\n",pentry->pw_gid);
	printf("Gecos: %s\n",pentry->pw_gecos);
	printf("Home dir: %s\n",pentry->pw_dir);
	exit(EXIT_SUCCESS);
}
